package com.example.myapp.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapp.R;
import com.example.myapp.adapter.ViewPagerAdapter;
import com.example.myapp.fragment.CategoryFragment;
import com.example.myapp.fragment.GamesFragment;
import com.example.myapp.fragment.RecommendFragment;
import com.example.myapp.fragment.TopListFragment;
import com.example.myapp.po.FragmentInfo;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment  extends Fragment {

    private ViewPager mViewPage;
    private TabLayout nav;
    private ViewPagerAdapter viewPagerAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.fragment_home,container,false);
        mViewPage=v.findViewById(R.id.continer);
        nav=v.findViewById(R.id.nav);

        viewPagerAdapter=new ViewPagerAdapter(getFragmentManager(),initFragments());
        mViewPage.setAdapter(viewPagerAdapter);
        nav.setupWithViewPager(mViewPage);

        return  v;

    }



    private List<FragmentInfo> initFragments(){
        List<FragmentInfo> mFragments = new ArrayList<>(4);
        mFragments.add(new FragmentInfo("推荐", RecommendFragment.class));
        mFragments.add(new FragmentInfo ("排行", TopListFragment.class));
        mFragments.add(new FragmentInfo ("游戏", GamesFragment.class));
        mFragments.add(new FragmentInfo ("分类", CategoryFragment.class));

        return  mFragments;
    }
}
